<?php
/**	
*	FILENAME: 		/server_app/new_registration.php
*	DESCRIPTION:	This script creates a new MyNova Mobile user account
*	AUTHOR:			Taylor Clifton
*	VERSION:		1.0.0
*	LAST MODIFIED:	02/15/10
**/

require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/users.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/libraries/functions.php");

enforceSSL();

$ldapUsername = $_POST["username"];
$UDID = $_POST["UDID"];
$pin = $_POST["pin"];

if (strlen($ldapUsername) == 0 || strlen($UDID) == 0 || strlen($pin) == 0) {
	$response["response_type"] = "error";
	$response["error_desc"] = "Username, password, or UDID not provided.";
	echo(json_encode($response));
} else {
	$encryptedPin = encryptPin($pin);									 
	$uid = addNewRegisteredUser($ldapUsername, $encryptedPin, $UDID);
	if ($uid !== FALSE) {
		$response["response_type"] = "success";
		$response["uid"] = $uid;
		echo(json_encode($response));
	} else {
		$response["response_type"] = "error";
		$response["error_desc"] = "User record was not successfully created";
		echo(json_encode($response));
	}
}
?>